package com.edu.jiangzhi.factory;

import com.edu.jiangzhi.domain.Animal;
import com.edu.jiangzhi.service.AnimalIntoIceboxService;
import com.edu.jiangzhi.service.impl.TigerIntoIceboxService;

import javax.swing.plaf.basic.BasicPanelUI;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author duweiping
 * service 工厂
 */
public class ServiceFactory {

    private ServiceFactory(){};

    private static final Map<String, AnimalIntoIceboxService>  MAP= new ConcurrentHashMap<>();

    static {
        MAP.put("Tiger", TigerIntoIceboxService.getInstance());
        // todo
    }

    /**
     * 获取实例
     * @param animal
     * @return
     */
    public AnimalIntoIceboxService getInstance(Animal animal) {
        // todo 判空，异常处理

        return MAP.getOrDefault(animal.getName(),MAP.get("Tiger"));
    }
}
